package com.zgh.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zgh.domain.Bbs;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BbsMapper extends BaseMapper<Bbs> {
    @Select("select * from bbs order by #{order} desc")
    List<Bbs> getAllBbsByTime(String order);

    @Update("update bbs set thumbs = #{thumb} where id = #{bbsId}")
    void thumb(String bbsId, int thumb);

    @Select("select comments from bbs where id = #{bbsId}")
    int selectComments(String bbsId);

    @Update("update bbs set comments = #{comments} where id = #{bbsId}")
    void updateComments(int comments,String bbsId);

//    @Select("<script>select id,coverUrl, title,content,thumbs+comments+views as hots,releaseTime from bbs " +
//            "<if test='provinceName != 全部'>" +
//            " where provinceName = #{provinceName}" +
//            " </if>" +
//            " order by hots desc limit 0,3" +
//            "</script>"
//    )
    @Select("select id,coverUrl, title,content,thumbs+comments+views as hots,releaseTime from bbs where provinceName = #{provinceName} order by hots desc limit 0,3")
    List<Bbs> findBbsByHots(String provinceName);
}
